package com.fph.design.strore.impl;

import com.alibaba.fastjson.JSON;
import com.fph.design.coupon.CouponResult;
import com.fph.design.coupon.CouponService;
import com.fph.design.strore.ICommodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 优惠券实现发奖的接口
 * @ClassName CouponCommodityService
 * @Description TODO
 * @Author fph
 * @Date 2024-07-09 15:20
 **/
public class CouponCommodityService implements ICommodity {

    private Logger logger = LoggerFactory.getLogger(CouponCommodityService.class);

    private CouponService couponService = new CouponService();
    @Override
    public void sendCommondity(String uID, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uID, bizId, commodityId);
        logger.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uID, commodityId, bizId, extMap);
        logger.info("测试结果[优惠券]：{}", JSON.toJSON(couponResult));
        if(!"0000".equals(couponResult.getCode())){
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}

